#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// 比较两个高精度数的大小
int compare_high_precision(const char *num1, const char *num2) {
    int len1 = strlen(num1);
    int len2 = strlen(num2);

    if (len1 != len2) {
        return len1 > len2 ? 1 : -1;
    }

    for (int i = 0; i < len1; i++) {
        if (num1[i] != num2[i]) {
            return num1[i] > num2[i] ? 1 : -1;
        }
    }

    return 0;
}

// 高精度乘法
char *multiply(char num1[], char num2[]) {
    int len1 = strlen(num1);
    int len2 = strlen(num2);
    int *intans = (int *)calloc(len1 + len2, sizeof(int));

    char *strans = (char *)malloc((len1 + len2 + 1) * sizeof(char));

    for (int i = 0; i < len1; i++) {
        for (int j = 0; j < len2; j++) {
            intans[i + j] += (num1[len1 - 1 - i] - '0') * (num2[len2 - 1 - j] - '0');
            intans[i + j + 1] += intans[i + j] / 10;
            intans[i + j] %= 10;
        }
    }

    int anslen = len1 + len2;
    while (anslen > 0 && intans[anslen - 1] == 0)
        anslen--;
    if (!anslen) {
        strans[0] = '0';
        strans[1] = '\0';
    } else {
        for (int i = 0; i < anslen; i++) {
            strans[anslen - 1 - i] = intans[i] + '0';
        }
        strans[anslen] = '\0';
    }

    free(intans);
    return strans;
}

// 高精度加法
char *add(char num1[], char num2[]) {
    int len1 = strlen(num1);
    int len2 = strlen(num2);
    int len = len1 > len2 ? len1 : len2;
    int anslen = len;
    int *intans = (int *)calloc(len + 1, sizeof(int));
    char *strans = (char *)malloc(len + 2 * sizeof(char));

    for (int i = 0; i < len1; i++) {
        intans[len1 - 1 - i] += num1[i] - '0';
    }

    for (int i = 0; i < len2; i++) {
        intans[len2 - 1 - i] += num2[i] - '0';
    }

    for (int i = 0; i < len; i++) {
        intans[i + 1] += intans[i] / 10;
        intans[i] %= 10;
    }

    if (intans[len])
        anslen++;

    if (!anslen) {
        strans[0] = '0';
        strans[1] = '\0';
    } else {
        for (int i = 0; i < anslen; i++) {
            strans[anslen - 1 - i] = intans[i] + '0';
        }
        strans[anslen] = '\0';
    }

    free(intans);
    return strans;
}


int main() {
    

    return 0;
}